package com.example.demo.controller;


import com.example.demo.common.Result;
import com.example.demo.mapper.UserFollowerMapper;
import com.example.demo.mapper.VideoAllReplyMapper;
import com.example.demo.service.UserFollowerService;
import com.example.demo.utils.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第五小组
 * @since 2021-08-10
 */
@RestController
@RequestMapping("/bilibili")
public class UserFollowerController {


    @Autowired
    UserFollowerService userFollowerService;

    @GetMapping("/fans")
    public Result fans(@RequestParam("uid") String uid, HttpServletResponse response){
        //爬取up主粉丝信息脚本太慢
        Util.exec("\\脚本\\user_follower.py",uid);
        return Result.succ(userFollowerService.listMaps());
    }

    @Resource
    UserFollowerMapper level_count;/*某用户（up主）粉丝等级分布统计*/

    @GetMapping("/level_count")
    public Result level_count(@RequestParam("uid") String uid , HttpServletResponse response) {
        Util.exec("\\脚本\\user_follower.py", uid);
        return Result.succ(level_count.level_count());
    }

    @Resource
    UserFollowerMapper vip_count;/*某用户（up主）粉丝会员分布统计*/
    @GetMapping("/vip_count")
    public Result vip_count(@RequestParam("uid") String uid , HttpServletResponse response) {
        Util.exec("\\脚本\\user_follower.py", uid);
        return Result.succ(vip_count.vip_count());
    }

    @Resource
    UserFollowerMapper sex_count;/*某用户（up主）粉丝性别分布统计*/
    @GetMapping("/sex_count")
    public Result sex_count(@RequestParam("uid") String uid , HttpServletResponse response) {
        Util.exec("\\脚本\\user_follower.py", uid);
        return Result.succ(sex_count.sex_count());
    }

    @Resource
    UserFollowerMapper time_count;/*某用户（up主）粉丝关注时间统计*/
    @GetMapping("/time_count")
    public Result day_count(@RequestParam("uid") String uid , HttpServletResponse response) {
        Util.exec("\\脚本\\user_follower.py", uid);
        return Result.succ(time_count.time_count());
    }
}
